package com.gimi.cloud.jimi.manage.controller.order;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.gimi.cloud.jimi.common.enums.ResponseCodeEnum;
import com.gimi.cloud.jimi.common.utils.JsonUtil;
import com.gimi.cloud.jimi.common.utils.reqhead.Response;
import com.gimi.cloud.jimi.common.utils.reqhead.Util;
import com.gimi.cloud.jimi.dto.order.OrderDTO;
import com.gimi.cloud.jimi.dto.order.OrderDTO.OrderStatus;
import com.gimi.cloud.jimi.manage.service.order.OrderService;
import com.github.pagehelper.PageInfo;
/**
 * 订单管理
 * @author chendi
 * @date 2018年1月10日
 */
@RestController
@RequestMapping(value = "order")
public class OrderController {
	
	@Autowired
    private OrderService orderService;
	
	/** 查询订单列表 */
    @RequestMapping(value = "/pageList")
    public void pageList(@RequestBody OrderDTO orderDTO, HttpServletResponse response) throws Exception {
    	Response resp = new Response();
    	PageInfo<OrderDTO> pageList = orderService.orderPageListByCondition(orderDTO);
        resp.setRes_data(pageList);
        resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
        Util.sendResponse(JsonUtil.toJSONStringWithDateFormatYYYYMMDDHHMMSS(resp), response);
    }
    /** 查询订单信息 */
    @RequestMapping(value = "/deleteOrder")
    public void deleteOrder(@RequestBody OrderDTO orderDTO, HttpServletResponse response) throws Exception {
    	Response resp = new Response();
    	orderService.deleteOrder(orderDTO);
    	resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
    	Util.sendResponse(JsonUtil.toJSONStringWithDateFormatYYYYMMDDHHMMSS(resp), response);
    }
    /** 更新订单状态信息 */
    @RequestMapping(value = "/orderStatus")
    public void orderStatus(@RequestBody @Validated({OrderStatus.class}) OrderDTO orderDTO, HttpServletResponse response) throws Exception {
    	Response resp = new Response();
    	orderService.orderStatus(orderDTO);
    	resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
    	Util.sendResponse(JsonUtil.toJSONStringWithDateFormatYYYYMMDDHHMMSS(resp), response);
    }
    /** 获得单个订单实体信息 */
    @RequestMapping(value = "/getSingleOrderBase")
    public void getSingleOrderBase(@RequestBody OrderDTO orderDTO, HttpServletResponse response) throws Exception {
    	Response resp = new Response();
    	OrderDTO dto = orderService.getSingleOrderBase(orderDTO);
    	resp.setRes_data(dto);
    	resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
    	Util.sendResponse(JsonUtil.toJSONStringWithDateFormatYYYYMMDDHHMMSS(resp), response);
    }
    /** 修改订单信息 */
    @RequestMapping(value = "/updateOrderBase")
    public void updateOrderBase(@RequestBody OrderDTO orderDTO, HttpServletResponse response) throws Exception {
    	Response resp = new Response();
    	orderService.updateOrderBase(orderDTO);
    	resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
    	Util.sendResponse(JsonUtil.toJSONStringWithDateFormatYYYYMMDDHHMMSS(resp), response);
    }
    /** 查询订单详细信息 */
    @RequestMapping(value = "/ShowOrderDetail")
    public void showOrderDetail(@RequestBody OrderDTO orderDTO, HttpServletResponse response) throws Exception {
    	Response resp = new Response();
    	OrderDTO orderDetail = orderService.ShowOrderDetail(orderDTO);
    	resp.setRes_data(orderDetail);
    	resp.setResponseCode(ResponseCodeEnum.SUCCESSED);
    	Util.sendResponse(JsonUtil.toJSONStringWithDateFormatYYYYMMDDHHMMSS(resp), response);
    }
    
}
